package com.letcoding.spiderAutoHome.job;

import lombok.extern.slf4j.Slf4j;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.quartz.QuartzJobBean;

/**
 * @ClassName CloseHttpConnectionJob
 * @Description 关闭无效连接        同步执行任务(单线程)
 * @Author will
 * @Date 2021/5/6 15:07
 * @Company 北京华焱坤泰科技有限公司
 */
@Slf4j
@DisallowConcurrentExecution
public class CloseHttpConnectionJob extends QuartzJobBean {
    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        ApplicationContext applicationContext = (ApplicationContext) context.getJobDetail().getJobDataMap().get("context");
        PoolingHttpClientConnectionManager httpClientPool = applicationContext.getBean(PoolingHttpClientConnectionManager.class);
        httpClientPool.closeExpiredConnections();
        log.info(">>>>>>>>>>>>>>>>>>>>>>>> closeExpiredConnections");
    }
}
